package com.qinker.oa.controller;

import com.qinker.oa.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class PageController {

    @RequestMapping("/")
    public String index(){
        return "/login.html";
    }

    @RequestMapping("/index")
    public String loginInSuccessFul(HttpSession httpSession){
        User loginUser = (User) httpSession.getAttribute("user");
        if (loginUser == null){
            return "redirect:login.html";
        }else {
            return "redirect:index.html";
        }
    }

    @RequestMapping("/work")
    public String toWorkPage(HttpSession session){
        User user = (User) session.getAttribute("user");
        if (user == null || !user.getRole().equalsIgnoreCase("user")){
            return "redirect:login.html";
        }else {
            return "redirect:work.html";
        }
    }

}
